﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOSingTowerMall;

namespace BLSingTowerMall
{
    public class ApprovalProcess
    {
        DBSingTowerMallEntities db = new DBSingTowerMallEntities();
        public IQueryable<EventHallBooking> getEVHBooking()
        {
            IQueryable<EventHallBooking> EHB = from ehb in db.EventHallBookings
                                               where ehb.Status == null
                                               select ehb;
            return EHB;
        }

        public IQueryable<EventHallBooking> getApprovedEVHBooking(int hallid)
        {
            IQueryable<EventHallBooking> EHB = from ehb in db.EventHallBookings
                                               where ehb.HallID==hallid &&
                                                             ehb.Status=="Approved"
                                               select ehb;
            return EHB;
        }

        public IQueryable<UserDetail> getUserDetail(string username)
        {
            //var user=db.aspnet_Users.Include("UserDetail")
            //    .Where(a=>a.UserName==Request.QueryString["UserName"]
            //    .Select(a=>a).to

            IQueryable<UserDetail> user = from a in db.aspnet_Users
                                          join u in db.UserDetails on a.UserId equals u.UserId
                                          where a.UserName == username
                                          select u;
            return user;

        }

        public List<EventHallBooking> GetEHBList()
        {
            {
                var ehb = db.EventHallBookings
                    //.Execute(System.Data.Objects.MergeOption.NoTracking)
                    //.OrderBy(a => new { a.HallID, a.UserName})
                    .Select(a => a).ToList();
                //           .Select(a => new { a.HallID, a.UserName }).ToList();
                return ehb;

                //foreach (EventHallBooking items in ehb)
                //{
                //    return items;
                //}
            }
        }

        public List<UserDetail> getUserDetailList(string username)
        {
            //var user = db.UserDetails
            //        .Join(db.aspnet_Users, a => a.UserId, b => b.UserId,
            //        (a, b) => new { UserDetails = a, aspnet_Users = b })
            //        .Where(b => b.aspnet_Users.UserName == username)
            //        .Select(a => a).ToList();

            var user = from u in db.UserDetails
                       join a in db.aspnet_Users on u.UserId equals a.UserId
                       where a.UserName == username
                       select u;
            return user.ToList();
        }

        public IQueryable<EventHallBooking> getEventHallBookingData(int bookingId)
        {
            System.Diagnostics.Debug.WriteLine("bookingid" + bookingId);

            IQueryable<EventHallBooking> ehb = from e in db.EventHallBookings
                                               where e.BookingID == bookingId
                                               select e;

            //var ehb = db.EventHallBookings
            //    .Where(a => a.BookingID == bookingId)
            //    .Select(a => a).ToList();
            return ehb;
        }

        public void getApproval()
        {
            //db.AddToEventHallBookings(ehb);
            db.SaveChanges();
        }









    }
}
